using HKB.Data.Dal;
using HKB.Data.Dal.S_VIPTableAdapters;
using HKB.Web;
using System;
using System.Data;
public class Shop_VIP
{
	private static readonly HLShop_VIPTableAdapter Adapter = new HLShop_VIPTableAdapter();
	public DataTable GetVipsBySalerIDUserID(int SalerID, int UserID)
	{
		return Shop_VIP.Adapter.GetVIPBySaleridUserID(SalerID, UserID);
	}
	public bool ISVIP(int SalerID, int UserID)
	{
		DataTable vIPBySaleridUserID = Shop_VIP.Adapter.GetVIPBySaleridUserID(SalerID, UserID);
		return vIPBySaleridUserID.Rows.Count > 0;
	}
	public bool AddVIPS(int SalerID, string UserID, int PresentExp, int PresentPoint, int TransCount, decimal TransMoney, string VIPLevel)
	{
		Shop_VIPCard shop_VIPCard = new Shop_VIPCard();
		DataTable vIPCardByOwerID = shop_VIPCard.GetVIPCardByOwerID(SalerID);
		bool result;
		if (vIPCardByOwerID.Rows.Count > 0)
		{
			int num = int.Parse(vIPCardByOwerID.Rows[0]["Card_ID"].ToString());
			S_VIP.HLShop_VIPDataTable hLShop_VIPDataTable = new S_VIP.HLShop_VIPDataTable();
			string[] array = UserID.Split(new char[]
			{
				','
			});
			for (int i = 0; i < array.Length; i++)
			{
				if (array[i].Trim() != "")
				{
					S_VIP.HLShop_VIPRow hLShop_VIPRow = hLShop_VIPDataTable.NewHLShop_VIPRow();
					hLShop_VIPRow.PresentExp = PresentExp;
					hLShop_VIPRow.PresentPoint = PresentPoint;
					hLShop_VIPRow.TransCount = TransCount;
					hLShop_VIPRow.TransMoney = TransMoney;
					hLShop_VIPRow.SalerID = SalerID;
					hLShop_VIPRow.UserID = int.Parse(array[i]);
					hLShop_VIPRow.VIPLevel = VIPLevel.Trim();
					hLShop_VIPDataTable.AddHLShop_VIPRow(hLShop_VIPRow);
				}
			}
			result = (Shop_VIP.Adapter.Update(hLShop_VIPDataTable) >= 1);
		}
		else
		{
			result = false;
		}
		return result;
	}
	public bool UpdateVIPS(string VIPID, int PresentExp, int PresentPoint, int TransCount, decimal TransMoney)
	{
		int num = 0;
		string[] array = VIPID.Split(new char[]
		{
			','
		});
		bool result;
		for (int i = 0; i < array.Length; i++)
		{
			if (array[i] != "")
			{
				S_VIP.HLShop_VIPDataTable singleVIPCard = Shop_VIP.Adapter.GetSingleVIPCard(int.Parse(array[i]));
				if (singleVIPCard.Rows.Count <= 0)
				{
					result = false;
					return result;
				}
				S_VIP.HLShop_VIPRow hLShop_VIPRow = singleVIPCard[0];
				hLShop_VIPRow.PresentExp += PresentExp;
				hLShop_VIPRow.PresentPoint += PresentPoint;
				hLShop_VIPRow.TransCount += TransCount;
				hLShop_VIPRow.TransMoney += TransMoney;
				Shop_VIPCard shop_VIPCard = new Shop_VIPCard();
				Shop_Shop shop_Shop = new Shop_Shop();
				int shopIDByShopOwerID = shop_Shop.GetShopIDByShopOwerID(hLShop_VIPRow.SalerID);
				DataTable vIPCardByShopID = shop_VIPCard.GetVIPCardByShopID(shopIDByShopOwerID);
				if (vIPCardByShopID.Rows.Count > 0)
				{
					bool flag = bool.Parse(vIPCardByShopID.Rows[0]["Isupgrade"].ToString());
					int num2 = int.Parse(vIPCardByShopID.Rows[0]["PresentExp1"].ToString());
					int num3 = int.Parse(vIPCardByShopID.Rows[0]["PresentPoint1"].ToString());
					int num4 = int.Parse(vIPCardByShopID.Rows[0]["TransCount1"].ToString());
					decimal d = decimal.Parse(vIPCardByShopID.Rows[0]["TransMoney1"].ToString());
					int num5 = int.Parse(vIPCardByShopID.Rows[0]["PresentExp2"].ToString());
					int num6 = int.Parse(vIPCardByShopID.Rows[0]["PresentPoint2"].ToString());
					int num7 = int.Parse(vIPCardByShopID.Rows[0]["TransCount2"].ToString());
					decimal d2 = decimal.Parse(vIPCardByShopID.Rows[0]["TransMoney2"].ToString());
					if (!flag)
					{
						if ((hLShop_VIPRow.PresentExp >= num2 && hLShop_VIPRow.PresentExp < num5) || (hLShop_VIPRow.PresentPoint >= num3 && hLShop_VIPRow.PresentPoint < num6) || (hLShop_VIPRow.TransCount >= num4 && hLShop_VIPRow.TransCount < num7) || (hLShop_VIPRow.TransMoney >= d && hLShop_VIPRow.TransMoney < d2))
						{
							hLShop_VIPRow.VIPLevel = "VIP会员";
						}
						else
						{
							if (hLShop_VIPRow.PresentExp >= num5 || hLShop_VIPRow.PresentPoint >= num6 || hLShop_VIPRow.TransCount >= num7 || hLShop_VIPRow.TransMoney >= d2)
							{
								hLShop_VIPRow.VIPLevel = "高级会员";
							}
							else
							{
								hLShop_VIPRow.VIPLevel = "普通会员";
							}
						}
					}
					else
					{
						if ((hLShop_VIPRow.PresentExp >= num2 && hLShop_VIPRow.PresentExp < num5) || (hLShop_VIPRow.PresentPoint >= num3 && hLShop_VIPRow.PresentPoint < num6) || (hLShop_VIPRow.TransCount >= num4 && hLShop_VIPRow.TransCount < num7) || (hLShop_VIPRow.TransMoney >= d && hLShop_VIPRow.TransMoney < d2))
						{
							if (hLShop_VIPRow.VIPLevel.Trim() != "高级会员")
							{
								hLShop_VIPRow.VIPLevel = "VIP会员";
							}
						}
						else
						{
							if (hLShop_VIPRow.PresentExp >= num5 || hLShop_VIPRow.PresentPoint >= num6 || hLShop_VIPRow.TransCount >= num7 || hLShop_VIPRow.TransMoney >= d2)
							{
								hLShop_VIPRow.VIPLevel = "高级会员";
							}
							else
							{
								if (hLShop_VIPRow.VIPLevel.Trim() != "高级会员" && hLShop_VIPRow.VIPLevel.Trim() != "VIP会员")
								{
									hLShop_VIPRow.VIPLevel = "普通会员";
								}
							}
						}
					}
				}
				if (Shop_VIP.Adapter.Update(hLShop_VIPRow) >= 1)
				{
					num++;
				}
			}
		}
		result = (num >= 1);
		return result;
	}
	public bool UpdateLevel(string VIPID, string VIPLevel)
	{
		int num = 0;
		string[] array = VIPID.Split(new char[]
		{
			','
		});
		int i = 0;
		bool result;
		while (i < array.Length)
		{
			if (array[i] != "")
			{
				S_VIP.HLShop_VIPDataTable singleVIPCard = Shop_VIP.Adapter.GetSingleVIPCard(int.Parse(array[i]));
				if (singleVIPCard.Rows.Count <= 0)
				{
					result = false;
					return result;
				}
				S_VIP.HLShop_VIPRow hLShop_VIPRow = singleVIPCard[0];
				Shop_VIPCard shop_VIPCard = new Shop_VIPCard();
				bool flag = bool.Parse(shop_VIPCard.GetSingleVIPCardByID(hLShop_VIPRow.CardID).Rows[0]["Isupgrade"].ToString());
				if (flag)
				{
					if (VIPLevel.Trim() == "普通会员" && hLShop_VIPRow.VIPLevel.Trim() == "高级会员")
					{
						goto IL_1A0;
					}
					if (VIPLevel.Trim() == "普通会员" && hLShop_VIPRow.VIPLevel.Trim() == "VIP会员")
					{
						goto IL_1A0;
					}
					if (VIPLevel.Trim() == "VIP会员" && hLShop_VIPRow.VIPLevel.Trim() == "高级会员")
					{
						goto IL_1A0;
					}
					hLShop_VIPRow.VIPLevel = VIPLevel.Trim();
				}
				else
				{
					hLShop_VIPRow.VIPLevel = VIPLevel.Trim();
				}
				if (Shop_VIP.Adapter.Update(hLShop_VIPRow) >= 1)
				{
					num++;
				}
			}
			IL_1A0:
			i++;
			continue;
			goto IL_1A0;
		}
		result = (num >= 1);
		return result;
	}
	public bool DeleteVIPS(string VIPID)
	{
		int num = 0;
		string[] array = VIPID.Split(new char[]
		{
			','
		});
		for (int i = 0; i < array.Length; i++)
		{
			if (array[i] != "")
			{
				if (Shop_VIP.Adapter.Delete(int.Parse(array[i])) >= 1)
				{
					num++;
				}
			}
		}
		return num >= 1;
	}
	public DataTable GetVIPByUserIDShopNameLevel(int UserID, string ShopName, string NickName, string Level)
	{
		return Shop_VIP.Adapter.GetVIPByUserIDShopNameNickNameLevel(new int?(UserID), ShopName, NickName, Level);
	}
	public DataTable GetSingleVIPCard(int VIPID)
	{
		return Shop_VIP.Adapter.GetSingleVIPCard(VIPID);
	}
	public DataTable GetVIPBySalerIDShopNameUserNameNickNameLevel(int SalerID, string ShaopName, string NickName, string Level)
	{
		return Shop_VIP.Adapter.GetVIPBySalerIDShopNameUserNameNickNameLevel(new int?(SalerID), ShaopName, NickName, Level);
	}
}
